package com.doxiaopu.students.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {
    /**
     * 配置上传文件路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/META-INF/resources/")
                .addResourceLocations("classpath:/resources/")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("classpath:/public/");
        //获取文件的真实路径
        String path = System.getProperty("user.dir")+"\\src\\main\\resources\\static\\images\\";
        //uploadFile对应resource下工程目录
        registry.addResourceHandler("/**").addResourceLocations("file:"+path);
//        registry.addResourceHandler("/**").addResourceLocations("file:D:\\ideaworkspace\\test\\src\\main\\resources\\static\\images\\");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
